//---------------------------------------------------------------------------


#pragma hdrstop

#include "ChessBoard.h"
#include <stdlib.h>
//---------------------------------------------------------------------------

#pragma package(smart_init)
//---------------------------------------------------------------------------
ChessBoard::ChessBoard(){
		int m[8][8] = {                 //-1 stand for white chessman
		{0,0,0,0,-1,-1,-1,-1},          //1 stand for black chessman
		{0,0,0,0,-1,-1,-1,-1},          //0 stand for no chessman
		{0,0,0,0,-1,-1,-1,-1},
		{0,0,0,0,0,0,0,0},
		{0,0,0,0,0,0,0,0},
		{1,1,1,1,0,0,0,0},
		{1,1,1,1,0,0,0,0},
		{1,1,1,1,0,0,0,0}
		};
		memcpy(map, m, sizeof(int)*64);
}
//---------------------------------------------------------------------------
void ChessBoard::CTransform(int& x, int& y){
		x = x / 50;
		y = y / 50;
}
//---------------------------------------------------------------------------
char ChessBoard::CheckChess(int a, int b){
		CTransform(a, b);
		return CheckGrid(a, b);
}
//---------------------------------------------------------------------------
char ChessBoard::CheckGrid(int a, int b){
		if (map[b][a] == 0){
				return NULL;
		}
		else{
				if (map[b][a] == 1){
						return 'B';
				}
		}
		return 'W';
}
//---------------------------------------------------------------------------
bool ChessBoard::BlackWin(){
		if (map[0][4]==1 && map[0][5]==1 && map[0][6]==1 && map[0][7]==1 && map[1][4]==1 && map[1][5]==1 && map[1][6]==1 && map[1][7]==1 && map[2][4]==1 && map[2][5]==1 && map[2][6]==1 && map[2][7]==1){
				return true;
		}
		return false;
}
//---------------------------------------------------------------------------
bool ChessBoard::WhiteWin(){
		if (map[5][0]==-1 && map[5][1]==-1 && map[5][2]==-1 && map[5][3]==-1 && map[6][0]==-1 && map[6][1]==-1 && map[6][2]==-1 && map[6][3]==-1 && map[7][0]==-1 && map[7][1]==-1 && map[7][2]==-1 && map[7][3]==-1){
				return true;
		}
		return false;
}
//---------------------------------------------------------------------------
void ChessBoard::UpdateMap(Pair fr, Pair to){
		CTransform(fr.x, fr.y);
		CTransform(to.x, to.y);
		//SavePath(&fr, &to);
		map[to.y][to.x] = map[fr.y][fr.x];
		map[fr.y][fr.x] = 0;
}
//---------------------------------------------------------------------------

